package com.lmx.persistence.service;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.exception.BusinessException;
import com.lmx.repoDomain.tmodel.NursingPlanExecute;
import com.lmx.repoDomain.tmodel.NursingServiceItemSign;

/**
 * 随时任务标签service实现
 *
 * @author ytche
 * @date 2017年9月9日
 *
 */
@Service
public class NursingServiceItemSignServiceImpl extends BaseCrudServiceImpl<NursingServiceItemSign>
		implements NursingServiceItemSignService {
	@Autowired
	NursingPlanExecuteService exeService;

	@Override
	public NursingServiceItemSign update(NursingServiceItemSign entity) {
		if (CommonConstants.DEL_STATUS_NO_0.equals(entity.getDelStatus())) {
			return super.update(entity);
		}
		NursingServiceItemSign sign = super.findOne(entity.getId());
		Set<NursingPlanExecute> exes = sign.getExes();
		if (exes == null || exes.size() == 0) {
			return super.update(entity);
		}
		for (NursingPlanExecute nursingPlanExecute : exes) {
			if (CommonConstants.DEL_STATUS_NO_0.equals(nursingPlanExecute.getDelStatus())) {
				throw new BusinessException("",
						CommonConstants.NURISNG_SIGN_ERROR.EXE_EXIST.lable(), "");
			}
		}
		return super.update(entity);
	}
}
